home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / audio / hippoplayer / support / examplescope.s next >
Text File  |  1995-09-15  |  12KB  |  594 lines

  1. *******************************************************************************
  2. *                         Example scope for HippoPlayer
  3. *                            By K-P Koljonen
  4. *******************************************************************************
  5. * Assembles with Asm-One v1.25, at least. Works on all Amiga configurations!
  6.  
  7.  
  8. *** Includes:
  9.  
  10.      incdir    include:
  11.     include    exec/exec_lib.i
  12.     include    exec/ports.i
  13.     include    exec/types.i
  14.     include    graphics/graphics_lib.i
  15.     include    graphics/rastport.i
  16.     include    intuition/intuition_lib.i
  17.     include    intuition/intuition.i
  18.     incdir
  19.  
  20. *** Some useful macros
  21.  
  22. lob    macro
  23.     jsr    _LVO\1(a6)
  24.     endm
  25.  
  26. lore    macro
  27.     ifc    "\1","Exec"
  28.     ifd    _ExecBase
  29.     ifeq    _ExecBase
  30.     move.l    (a5),a6
  31.     else
  32.     move.l    _ExecBase(a5),a6
  33.     endc
  34.     else
  35.     move.l    4.w,a6
  36.     endc
  37.     else
  38.     move.l    _\1Base(a5),a6
  39.     endc
  40.     jsr    _LVO\2(a6)
  41.     endm
  42.  
  43. pushm    macro
  44.     ifc    "\1","all"
  45.     movem.l    d0-a6,-(sp)
  46.     else
  47.     movem.l    \1,-(sp)
  48.     endc
  49.     endm
  50.  
  51. popm    macro
  52.     ifc    "\1","all"
  53.     movem.l    (sp)+,d0-a6
  54.     else
  55.     movem.l    (sp)+,\1
  56.     endc
  57.     endm
  58.  
  59. push    macro
  60.     move.l    \1,-(sp)
  61.     endm
  62.  
  63. pop    macro
  64.     move.l    (sp)+,\1
  65.     endm
  66.  
  67.  
  68.  
  69. *** HippoPlayer's port:
  70.  
  71.     STRUCTURE    HippoPort,MP_SIZE
  72.     LONG        hip_private1    * Private..
  73.     APTR        hip_kplbase    * kplbase address
  74.     WORD        hip_reserved0    * Private..
  75.     BYTE        hip_reserved1    * Private..
  76.     BYTE        hip_opencount    * Open count
  77.     BYTE        hip_mainvolume    * Main volume, 0-64
  78.     BYTE        hip_play    * If non-zero, HiP is playing
  79.     BYTE        hip_playertype     * 33 = Protracker, 49 = PS3M. 
  80.     *** Protracker ***
  81.     BYTE        hip_reserved2
  82.     APTR        hip_PTch1    * Protracker channel data for ch1
  83.     APTR        hip_PTch2    * ch2
  84.     APTR        hip_PTch3    * ch3
  85.     APTR        hip_PTch4    * ch4
  86.     *** PS3M ***
  87.     APTR        hip_ps3mleft    * Buffer for the left side
  88.     APTR        hip_ps3mright    * Buffer for the right side
  89.     LONG        hip_ps3moffs    * Playing position
  90.     LONG        hip_ps3mmaxoffs    * Max value for hip_ps3moffs
  91.  
  92.     BYTE        hip_PTtrigger1
  93.     BYTE        hip_PTtrigger2
  94.     BYTE        hip_PTtrigger3
  95.     BYTE        hip_PTtrigger4
  96.  
  97.     LABEL        HippoPort_SIZEOF 
  98.  
  99.     *** PT channel data block
  100.     STRUCTURE    PTch,0
  101.     LONG        PTch_start    * Start address of sample
  102.     WORD        PTch_length    * Length of sample in words
  103.     LONG        PTch_loopstart    * Start address of loop
  104.     WORD        PTch_replen    * Loop length in words
  105.     WORD        PTch_volume    * Channel volume
  106.     WORD        PTch_period    * Channel period
  107.     WORD        PTch_private1    * Private...
  108.  
  109. *** Dimensions:
  110.  
  111. WIDTH    =    320    
  112. HEIGHT    =    64
  113.  
  114. *** Variables:
  115.  
  116.     rsreset
  117. _ExecBase    rs.l    1
  118. _GFXBase    rs.l    1
  119. _IntuiBase    rs.l    1
  120. port        rs.l    1
  121. owntask        rs.l    1
  122. screenlock    rs.l    1
  123. oldpri        rs.l    1
  124. windowbase    rs.l    1
  125. rastport    rs.l    1
  126. userport    rs.l    1
  127. windowtop    rs    1
  128. windowright    rs    1
  129. windowleft    rs    1
  130. windowbottom    rs    1
  131. draw1        rs.l    1
  132. draw2        rs.l    1
  133. omabitmap    rs.b    bm_SIZEOF
  134. size_var    rs.b    0
  135.  
  136. *** Main program
  137.  
  138. main    lea    var_b,a5        * Store execbase
  139.     move.l    4.w,a6
  140.     move.l    a6,(a5)
  141.     
  142.     sub.l    a1,a1            * Find our process
  143.     lob    FindTask
  144.     move.l    d0,owntask(a5)
  145.  
  146.     lea    intuiname(pc),a1    * Open libs
  147.     lore    Exec,OldOpenLibrary
  148.     move.l    d0,_IntuiBase(a5)
  149.  
  150.     lea     gfxname(pc),a1        
  151.     lob    OldOpenLibrary
  152.     move.l    d0,_GFXBase(a5)
  153.  
  154. *** Try to find HippoPlayer's port. If succesfull, add 1 to hip_opencount
  155. *** indicating we are using the information in the port.
  156. *** Protect this procedure with Forbid()-Permit()!
  157.  
  158.     lob    Forbid
  159.     lea    portname(pc),a1
  160.     lob    FindPort
  161.     move.l    d0,port(a5)
  162.     beq.w    exit
  163.     move.l    d0,a0
  164.     addq.b    #1,hip_opencount(a0)    * We are using the port now!
  165.     lob    Permit
  166.  
  167. *** Get some info about the screen we're running on
  168.  
  169.     bsr.w    getscreendata
  170.  
  171. *** Open our window
  172.  
  173.     lea    winstruc,a0
  174.     lore    Intui,OpenWindow
  175.     move.l    d0,windowbase(a5)
  176.     beq.w    exit
  177.     move.l    d0,a0
  178.     move.l    wd_RPort(a0),rastport(a5)    * Store rastport and userport
  179.     move.l    wd_UserPort(a0),userport(a5)
  180.  
  181. *** Draw a bevel box
  182.  
  183. plx1    equr    d4
  184. plx2    equr    d5
  185. ply1    equr    d6
  186. ply2    equr    d7
  187.  
  188.     moveq   #8,plx1
  189.     move    #331,plx2
  190.     moveq   #13,ply1
  191.     moveq   #80,ply2
  192.     add    windowleft(a5),plx1
  193.     add    windowleft(a5),plx2
  194.     add    windowtop(a5),ply1
  195.     add    windowtop(a5),ply2
  196.     move.l    rastport(a5),a2
  197.     bsr.w    piirra_loota2
  198.     subq    #1,plx1
  199.     addq    #1,plx2
  200.     bsr.w    piirra_loota2a
  201.  
  202. *** Initialize the bitmap structure
  203.  
  204.     lea    omabitmap(a5),a0
  205.     moveq    #1,d0            * depth (1 bitplane)
  206.     move    #WIDTH,d1        * width
  207.     move    #HEIGHT,d2        * height 
  208.     lore    GFX,InitBitMap
  209.     move.l    #buffer1,omabitmap+bm_Planes(a5) * Plane pointer
  210.  
  211.     move.l    #buffer1,draw1(a5)    * Buffer pointers for drawing
  212.     move.l    #buffer2,draw2(a5)
  213.  
  214. *** Set task priority to -30 to prevent messing up with other programs
  215.  
  216.     move.l    owntask(a5),a1        
  217.     moveq    #-30,d0
  218.     lore    Exec,SetTaskPri
  219.     move.l    d0,oldpri(a5)        * Store the old priority
  220.  
  221. *** Main loop begins here
  222.  
  223. loop    move.l    _GFXBase(a5),a6        * Wait a while..
  224.     lob    WaitTOF
  225.  
  226.     move.l    port(a5),a0        * Check if HiP is playing
  227.     tst.b    hip_play(a0)
  228.     beq.b    .oh
  229.     bsr.w    dung            * Do the scope
  230. .oh
  231.     move.l    userport(a5),a0        * Get messages from IDCMP
  232.     lore    Exec,GetMsg
  233.     tst.l    d0
  234.     beq.b    loop
  235.     move.l    d0,a1
  236.  
  237.     move.l    im_Class(a1),d2        
  238.     lob    ReplyMsg
  239.     cmp.l    #IDCMP_CLOSEWINDOW,d2    * Should we exit?
  240.     bne.b    loop            * No. Keep loopin'
  241.     
  242.     move.l    owntask(a5),a1        * Restore the old priority
  243.     move.l    oldpri(a5),d0
  244.     lore    Exec,SetTaskPri
  245.  
  246. exit
  247.  
  248. *** Exit program
  249.     
  250.     move.l    port(a5),d0        * IMPORTANT! Subtract 1 from
  251.     beq.b    .uh0            * hip_opencount when the port is not
  252.     move.l    d0,a0            * needed anymore!
  253.     subq.b    #1,hip_opencount(a0)
  254. .uh0
  255.  
  256.     move.l    windowbase(a5),d0    * Close the window
  257.     beq.b    .uh1
  258.     move.l    d0,a0
  259.     lore    Intui,CloseWindow
  260. .uh1
  261.     move.l    _IntuiBase(a5),a1    * And the libs
  262.     lore    Exec,CloseLibrary
  263.     move.l    _GFXBase(a5),a1
  264.     lob    CloseLibrary
  265.  
  266.     moveq    #0,d0            * No error
  267.     rts
  268.     
  269. ***** Get some info about the screen we're running on
  270.  
  271. getscreendata
  272.     move.l    (a5),a0            * Running kick2.0 or newer?
  273.     cmp    #37,LIB_VERSION(a0)
  274.     bhs.b    .new        
  275.     rts                
  276. .new                    * Yes.
  277.     
  278.     sub.l    a0,a0            * Default public screen
  279.     lore    Intui,LockPubScreen      * Kick2.0+ function
  280.     move.l    d0,d7
  281.     beq.b    exit
  282.  
  283.     move.l    d0,a0            * Store the values
  284.     move.b    sc_BarHeight(a0),windowtop+1(a5) 
  285.     move.b    sc_WBorLeft(a0),windowleft+1(a5)
  286.     move.b    sc_WBorRight(a0),windowright+1(a5)
  287.     move.b    sc_WBorBottom(a0),windowbottom+1(a5)
  288.     subq    #4,windowleft(a5)
  289.     subq    #4,windowright(a5)
  290.     subq    #2,windowbottom(a5)
  291.     sub    #10,windowtop(a5)
  292.     bpl.b    .olde
  293.     clr    windowtop(a5)
  294. .olde
  295.     move    windowtop(a5),d0    * Adjust the window size
  296.     add    d0,winstruc+nw_Height
  297.     move    windowleft(a5),d1
  298.     add    d1,winstruc+nw_Width
  299.     move    windowbottom(a5),d3
  300.     add    d3,winstruc+nw_Height
  301.  
  302.     move.l    d7,a1            * Unlock it. Let's hope it doesn't
  303.     sub.l    a0,a0            * go anywhere before we open our
  304.     lob    UnlockPubScreen        * window ;-)
  305.     rts
  306.  
  307.  
  308. *** Draw a bevel box
  309.  
  310. piirra_loota2a
  311.     pushm    all
  312.     moveq    #1,d3
  313.     bra.b    prl
  314.  
  315. piirra_loota2
  316.     pushm    all
  317.     moveq    #0,d3
  318. prl
  319.     move.l    rastport(a5),a2
  320.     move    #1,a3
  321.     move    #2,a4
  322.  
  323.     move.l    _GFXBase(a5),a6
  324.     move.l    a3,d0
  325.     move.l    a2,a1
  326.     lob    SetAPen
  327.  
  328.     move.l    plx1,d0
  329.     move.l    ply2,d1
  330.     lob    Move
  331.     move.l    a2,a1
  332.     move.l    plx1,d0
  333.     move.l    ply1,d1
  334.     lob    Draw
  335.  
  336.     move.l    a2,a1
  337.     move.l    plx2,d0
  338.     move.l    ply1,d1
  339.     lob    Draw
  340.  
  341.     move.l    a2,a1
  342.     move.l    a4,d0
  343.     lob    SetAPen
  344.  
  345.     move.l    a2,a1
  346.     move.l    plx2,d0
  347.     move.l    ply1,d1
  348.     addq.l    #1,d1
  349.     sub.l    d3,d1
  350.     lob    Move
  351.     move.l    a2,a1
  352.     move.l    plx2,d0
  353.     move.l    ply2,d1
  354.     lob    Draw
  355.  
  356.     move.l    a2,a1
  357.     move.l    plx1,d0
  358.     addq.l    #1,d0
  359.     move.l    ply2,d1
  360.     lob    Draw
  361.  
  362.     move.l    a2,a1
  363.     moveq    #1,d0
  364.     lob    SetAPen
  365.  
  366.     popm    all
  367.     rts
  368.  
  369.  
  370.  
  371. *** Display the scope
  372.  
  373. * I have two buffers, one for drawing and one for clearing.
  374. * Clearing is done with blitter during which cpu draws into the other
  375. * buffer. The drawn buffer is then dumped into the window using
  376. * BltBitMapRastPort().  If someone knows a faster way for doing this please
  377. * tell me.
  378.  
  379. dung
  380.     move.l    _GFXBase(a5),a6        * Grab the blitter
  381.     lob    OwnBlitter
  382.     lob    WaitBlit
  383.  
  384.     move.l    draw2(a5),$dff054    * Clear the drawing area
  385.     move    #0,$dff066
  386.     move.l    #$01000000,$dff040
  387.     move    #HEIGHT*64+WIDTH/16,$dff058
  388.  
  389.     lob    DisownBlitter        * Free the blitter
  390.  
  391.     pushm    all
  392.     move.l    port(a5),a0
  393.     cmp.b    #33,hip_playertype(a0)    * Protracker?
  394.     beq.b    .1
  395.     cmp.b    #49,hip_playertype(a0)    * PS3M?
  396.     beq.b    .2
  397.     bra.b    .3
  398. .1    bsr.b    quadrascope        * Quadrascope for PT
  399.     bra.b    .3
  400. .2    bsr.w    multiscope        * Stereoscope for PS3M
  401. .3    popm    all
  402.  
  403.     movem.l    draw1(a5),d0/d1        * Switch the buffers
  404.     exg    d0,d1
  405.     movem.l    d0/d1,draw1(a5)
  406.  
  407.     lea    omabitmap(a5),a0    * Set the bitplane pointer
  408.     move.l    d1,bm_Planes(a0)
  409.  
  410. ;    lea    omabitmap(a5),a0    * Copy from bitmap to rastport
  411.     move.l    rastport(a5),a1
  412.     moveq    #0,d0        * source x,y
  413.     moveq    #0,d1
  414.     moveq    #10,d2        * dest x,y
  415.     moveq    #15,d3
  416.     add    windowleft(a5),d2
  417.     add    windowtop(a5),d3
  418.     move.l    #$c0,d6        * minterm a->d
  419.     move.l    #WIDTH,d4    * x-size
  420.     move    #HEIGHT,d5    * y-size
  421.     lore    GFX,BltBitMapRastPort    * Zwoosh!
  422.     rts
  423.  
  424. *** Quarascope routine for Protracker
  425.  
  426. * This (and the stereoscope) are very unoptimized. The reason for this is
  427. * that unoptimized code is usually easier to understand than optimized code.
  428. * Also this leaves a certain challenge for coders to try to get the loop
  429. * as fast as possible.
  430.  
  431. quadrascope
  432.     move.l    port(a5),a3
  433.     move.l    hip_PTch1(a3),a3    * Channel 1 data
  434.     move.l    draw1(a5),a0        
  435.     bsr.b    .scope
  436.  
  437. * WIDTH/8/4 = 10
  438.  
  439.     move.l    port(a5),a3
  440.     move.l    hip_PTch2(a3),a3
  441.     move.l    draw1(a5),a0
  442.     lea    10(a0),a0        * Position
  443.     bsr.b    .scope
  444.  
  445.     move.l    port(a5),a3
  446.     move.l    hip_PTch3(a3),a3
  447.     move.l    draw1(a5),a0
  448.     lea    10+10(a0),a0
  449.     bsr.b    .scope
  450.  
  451.     move.l    port(a5),a3
  452.     move.l    hip_PTch4(a3),a3
  453.     move.l    draw1(a5),a0
  454.     lea    10+10+10(a0),a0
  455.     bsr.b    .scope
  456.     rts
  457.  
  458. .scope
  459.     tst.l    PTch_loopstart(a3)    * Always check these to avoid
  460.     beq.b    .halt            * enforcer hits!
  461.     move.l    PTch_start(a3),d0
  462.     bne.b    .jolt
  463. .halt    rts
  464.  
  465. .jolt    
  466.     move.l    d0,a1                * Sample start
  467.     move    PTch_length(a3),d5        * Sample length
  468.  
  469.     move.l    port(a5),a2        * Get mainvolume
  470.     moveq    #0,d1
  471.     move.b    hip_mainvolume(a2),d1    * (Main volume * sample volume)/64
  472.     mulu    PTch_volume(a3),d1    
  473.     lsr    #6,d1            * Value for scaling the data
  474.  
  475.     moveq    #0,d0            * X coordinate
  476.     moveq    #80-1,d7        * Loop counter, do 80 pixels
  477. drlo    
  478.     move.b    (a1)+,d2        * Read one byte sample data
  479.     ext    d2            * Sign extend to word
  480.     muls    d1,d2            * Scale according to volume
  481.     asr    #6,d2            * ...
  482.     add    #$80,d2            * Change the sign
  483.     asr    #2,d2            * Scale down to 0-63
  484.     mulu    #WIDTH/8,d2        * Get Y coordinate in the bitplane
  485.  
  486.     move    d0,d4            * X
  487.     move    d0,d3
  488.     lsr    #3,d4            * X offset in bytes = x-coord/8
  489.     add    d4,d2            * Add to Y
  490.     not    d3            * Plot pixel
  491.     bset    d3,(a0,d2)        * ...
  492.  
  493.     subq    #1,d5            * Subtract sample length
  494.     bpl.b    .l            * sample end?
  495.     move    PTch_replen(a3),d5    * Get values for loop 
  496.     move.l    PTch_loopstart(a3),a1
  497. .l
  498.     addq    #1,d0        * Increase X
  499.  
  500.     dbf    d7,drlo        * Loop..
  501.     rts
  502.  
  503.  
  504.  
  505. *** Stereoscope for PS3M
  506.  
  507. multiscope
  508.     move.l    port(a5),a1
  509.     move.l    hip_ps3mleft(a1),a1
  510.     move.l    draw1(a5),a0
  511.     bsr.b    .h
  512.  
  513.     move.l    port(a5),a1
  514.     move.l    hip_ps3mright(a1),a1
  515.     move.l    draw1(a5),a0
  516.     lea    WIDTH/8/2(a0),a0
  517.     bsr.b    .h
  518.     rts
  519.  
  520. .h    move.l    port(a5),a2
  521.     move.l    hip_ps3moffs(a2),d5        * Get offset in buffers
  522.     move.l    hip_ps3mmaxoffs(a2),d4        * Get max offset
  523.         
  524.     move    #160-1,d7        * Draw 160 pixels
  525.     moveq    #0,d0            * X coord
  526. .drlo    
  527.     moveq    #0,d2
  528.     move.b    (a1,d5.l),d2        * Get data from mixing buffer
  529.     add.b    #$80,d2
  530.     lsr    #2,d2
  531.     mulu    #WIDTH/8,d2        * Y
  532.  
  533.     move    d0,d6
  534.     move    d0,d3
  535.     lsr    #3,d6            * X offset in bytes = x-coord/8
  536.     add    d6,d2            
  537.     not    d3            * Plot pixel
  538.     bset    d3,(a0,d2)        * ...
  539.  
  540.     addq    #1,d0            * Increase x coord
  541.     addq.l    #1,d5            * Increase buffer position
  542.     and.l    d4,d5            * make sure it stays in the buffer
  543.  
  544.     dbf    d7,.drlo        * Loop
  545.     rts
  546.  
  547.  
  548.  
  549. *******************************************************************************
  550. * Window
  551.  
  552. wflags     = WFLG_SMART_REFRESH!WFLG_DRAGBAR!WFLG_CLOSEGADGET!WFLG_DEPTHGADGET
  553. idcmpflags = IDCMP_CLOSEWINDOW
  554.  
  555. winstruc
  556.     dc    110,85    * x,y position
  557. winsiz    dc    340,85    * x,y size
  558.     dc.b    2,1    
  559.     dc.l    idcmpflags
  560.     dc.l    wflags
  561.     dc.l    0
  562.     dc.l    0    
  563.     dc.l    .t    * title
  564.     dc.l    0
  565.     dc.l    0    
  566.     dc    0,640    * min/max x
  567.     dc    0,256    * min/max y
  568.     dc    WBENCHSCREEN
  569.     dc.l    0
  570.  
  571. .t    dc.b    "HiP - Example scope",0
  572.  
  573. intuiname    dc.b    "intuition.library",0
  574. gfxname        dc.b    "graphics.library",0
  575. dosname        dc.b    "dos.library",0
  576. portname    dc.b    "HiP-Port",0
  577.  even
  578.  
  579.  
  580.      section    udnm,bss_p
  581.  
  582. * Variables
  583.  
  584. var_b        ds.b    size_var
  585.  
  586.     section    hihi,bss_c
  587.  
  588. * GFX buffers
  589.  
  590. buffer1    ds.b    WIDTH/8*HEIGHT
  591. buffer2    ds.b    WIDTH/8*HEIGHT
  592.  
  593.  end
  594.